﻿using Bentley.CifNET.GeometryModel.SDK;
using CheccCoverplateCulvertAssemble.Common;
using CheccCoverplateCulvertAssemble.run;
using CheccCoverplateCulvertAssemble.Tools;
using CheccCoverplateCulvertAssemble.util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CheccCoverplateCulvertAssemble.FormColl
{
    public partial class SelectLines : Form
    {
        public delegate void SetLineDatas(List<AlignmentProperty> alignments);
        public delegate void SetTxtData();
        SetTxtData _setTxtData;
        List<AlignmentProperty> selectAlignments = new List<AlignmentProperty>();
        SelectAlignmentTool selectAlignment = null;
        public SelectLines(SetTxtData setTxtData)
        {
            this._setTxtData = setTxtData;
            #region 界面设置
            //使最大化窗口失效
            this.MaximizeBox = false;
            //禁止对窗口大小进行拖拽
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            //窗口位置
            this.StartPosition = FormStartPosition.CenterScreen;
            //窗口置顶
            this.TopMost = true;
            #endregion
            InitializeComponent();
            //窗体控件适应屏幕分辨率
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
            this.Icon = Properties.Resources.Culvert;
        }

        void SetLabelData(List<AlignmentProperty> alignments)
        {
            selectAlignments = alignments;
            var stakeMarkData = StakeMarkTransistion(alignments);
            for (int i = 0; i < stakeMarkData.Count; i++)
            {
                switch (i)
                {
                    case 0:
                        lab_MainLine.Text = stakeMarkData[0];
                        break;
                    case 1:
                        lab_MainLine.Text = stakeMarkData[0];
                        lab_SecondLine.Text = stakeMarkData[1];
                        break;
                    case 2:
                        lab_MainLine.Text = stakeMarkData[0];
                        lab_SecondLine.Text = stakeMarkData[1];
                        lab_ThirdLine.Text = stakeMarkData[2];
                        break;
                }
            }
        }
        List<string> StakeMarkTransistion(List<AlignmentProperty> alignmentProperties)
        {
            List<string> strings = new List<string>();
            string sta;
            string end;
            for (int i = 0; i < alignmentProperties.Count; i++)
            {
                switch (i)
                {
                    case 0:
                        sta = StationConvert.ConvertZH(alignmentProperties[0].StationPrefix, alignmentProperties[0].StaStation);
                        end = StationConvert.ConvertZH(alignmentProperties[0].StationPrefix, alignmentProperties[0].EndStation);
                        strings.Add(sta + "～" + end);
                        break;
                    case 1:
                        sta = StationConvert.ConvertZH(alignmentProperties[1].StationPrefix, alignmentProperties[1].StaStation);
                        end = StationConvert.ConvertZH(alignmentProperties[1].StationPrefix, alignmentProperties[1].EndStation);
                        strings.Add(sta + "～" + end);
                        break;
                    case 2:
                        sta = StationConvert.ConvertZH(alignmentProperties[2].StationPrefix, alignmentProperties[2].StaStation);
                        end = StationConvert.ConvertZH(alignmentProperties[2].StationPrefix, alignmentProperties[2].EndStation);
                        strings.Add(sta + "～" + end);
                        break;
                }
            }
            return strings;
        }

        private void SelectLines_FormClosing(object sender, FormClosingEventArgs e)
        {
            _setTxtData();
            Commands.mainForm.Show();
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {

        }

        private void btn_Select_Click(object sender, EventArgs e)
        {
            selectAlignment = new SelectAlignmentTool(this, SetLabelData);
            selectAlignment.InstallTool();
        }

        private void btn_ClearSelect_Click(object sender, EventArgs e)
        {
            lab_MainLine.Text = "";
            lab_SecondLine.Text = "";
            lab_ThirdLine.Text = "";
            if (selectAlignment != null) selectAlignment.ClearAligmentData();
        }

        private void btn_Sure_Click(object sender, EventArgs e)
        {
            if (selectAlignments.Count != 0)
            {
                CommonData.Instance.CommomTotal.SelectAlignments = selectAlignments;
                Commands.mainForm.lab_alignmentInfo.Text = GetLabelPro(selectAlignments[0].ThisAlignment);
            }
            this.Close();
        }

        private string GetLabelPro(Alignment alignment)
        {
            if (alignment == null)
            {
                return string.Empty;
            }
            string highwayClassification = ElementProperty.GetElePropertyValue(alignment.DgnECInstance.Element, "公路等级");
            string GLSS = ElementProperty.GetElePropertyValue(alignment.DgnECInstance.Element, "设计时速(km/h)");
            string baseWidth = ElementProperty.GetElePropertyValue(alignment.DgnECInstance.Element, "路基宽度(米)");
            string antiKnock = ElementProperty.GetElePropertyValue(alignment.DgnECInstance.Element, "抗震烈度");
            string autoLoad = ElementProperty.GetElePropertyValue(alignment.DgnECInstance.Element, "汽车荷载");
            string environmentType = ElementProperty.GetElePropertyValue(alignment.DgnECInstance.Element, "环境类别");
            string str = highwayClassification + "、" + GLSS + "(km/h)" + "、" + baseWidth + "m" + "、" + antiKnock + "、" + autoLoad + "、" + environmentType;
            return str;
        }

        private void SelectLines_Load(object sender, EventArgs e)
        {

        }
    }
}
